﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;


namespace BizCollegeWebApp.Models
{

    [System.ComponentModel.DataAnnotations.MetadataType(typeof(User.UserMetadata))]
    public partial class User
    {
        private class UserMetadata
        {
            [RegularExpression("^[a-zA-Z0-9]+${4,20}", ErrorMessage = "Please enter a valid Username with a minimum of six characters and a maximum of 8 characters")]
            [Required]
            public string Username;

            [RegularExpression("([A-Za-z0-9_]|[!@#$%]){6,15}", ErrorMessage = "Please enter an alphanumeric password of minimum 6 characters and a maximum of 15 characters")]
            [Required]
            public string Password;

            [RegularExpression("^([A-Za-z]){2,15}", ErrorMessage = "Please enter a valid firstname")]
            [Required]
            public string FirstName;

            [RegularExpression("^([A-Za-z]){2,15}", ErrorMessage = "Please enter a valid lastname")]
            [Required]
            public string LastName;

            [Required]
            [RegularExpression("^[0-9]+\\s+([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)$", ErrorMessage = "Please enter a valid address")]
            public string Adress;

            [RegularExpression("^([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)$", ErrorMessage = "Please enter a valid name for city")]
            [Required]
            public string City;

            [RegularExpression("(^[0-9]{5})", ErrorMessage = "Please enter a valid 5 digit US zipcode")]
            [Required]
            public string Zip;

            [RegularExpression("(^([0-9]{3}[-][0-9]{3}[-][0-9]{4}))$", ErrorMessage = "Please enter a valid US phone number as xxx-xxx-xxxx")]
            [Required]
            public string Phone;

            [RegularExpression(@"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")] 
            [Required]
            public string Email;
        }

        public bool IsEnrolled(int CourseID)
        {
            BizCollegeDBDataContext db = new BizCollegeDBDataContext();
            return db.Enrollments.Any(e => e.CourseID == CourseID && e.UserID == ID);
        }
    }
}

